<?php

namespace app\controller\admin;

use app\BaseController;
use app\Code;
use app\model\CareerShowcase;
use app\service\CareerService;
use app\validate\CareerValidate;
use think\exception\ValidateException;
use think\facade\Request;
use think\facade\Log;
use app\validate\CareerShowcaseValidate;


class CareerController extends BaseController
{

    protected $careerService;

    // 使用依赖注入
    public function __construct(CareerService $careerService)
    {
        $this->careerService = $careerService;
    }

    // 添加职业风采
    public function create()
    {

        $data = Request::post();

        try {
            // 数据验证
            validate(CareerValidate::class)->check($data);

            $showcase = $this->careerService->createCareer($data);

            return $this->returnJson($showcase);
        }catch (ValidateException $e) {

            return $this->returnJson([], Code::BAD_REQUEST, $e->getMessage());

        } catch (\Exception $e) {
            Log::error("添加职业风采失败: " . $e->getMessage());
            return $this->returnJson([], Code::SERVER_ERROR, '服务器错误，请稍后再试');
        }
    }
}